package ma.mindware.mpm.util;


import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Enumeration;
import java.util.ResourceBundle;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import org.json.JSONObject;



import com.opensymphony.xwork2.ActionSupport;


public class Translator extends ActionSupport {
	
	private InputStream data;
	
	
	private HttpSession session =ServletActionContext.getRequest().getSession();
	
	public InputStream getData() {
		return data;
	}
	

	public void setData(InputStream data) {
		this.data = data;
	}
	
	public String getTranslator(){
		ResourceBundle labels =
		    ResourceBundle.getBundle("i18n/language", getLocale());
		Enumeration bundleKeys = labels.getKeys();
		
		JSONObject jsonObject=new JSONObject();
		while (bundleKeys.hasMoreElements()) {
		    String key = (String)bundleKeys.nextElement();
		    String value = labels.getString(key);
		    jsonObject.put(key, value);
		}
		
		JSONObject jsonMain=new JSONObject();
		jsonMain.put("translator", jsonObject);
		data=new StringBufferInputStream(jsonMain.toString());
		return SUCCESS;
		
	}
	
}